#ifndef USER_REPOSITORY_H
#define USER_REPOSITORY_H

#include "base_repository.h"
#include "user.h"
#include "sqlite_wrapper.h"
#include <string>

/// @file user_repository.h
/// @brief Repository for User table operations
/// 
/// This file defines the repository class for User table operations
/// using the SQLite C API with RAII wrappers. Inherits from BaseRepository for
/// common CRUD operations.

/// @class UserRepository
/// @brief Repository class for User table operations
/// 
/// This class provides database operations for User entities.
/// Inherits from BaseRepository for common CRUD operations.
class UserRepository : public BaseRepository<User> {
private:
    DatabaseConnection& db_;

public:
    /// @brief Constructor
    /// @param db Reference to the DatabaseConnection object
    UserRepository(DatabaseConnection& db) : db_(db) {}
    
    /// @brief Create a new user in the database
    /// @param user Reference to the user to create
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int create(User& user) override;

    /// @brief Update an existing user in the database
    /// @param user Reference to the user to update
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int update(const User& user) override;

    /// @brief Remove a user from the database by ID
    /// @param id The ID of the user to remove
    /// @return REPO_SUCCESS on success, REPO_ERROR_DATABASE on failure
    virtual int remove(int id) override;

    /// @brief Find a user by ID
    /// @param id The ID of the user to find
    /// @return Optional containing the user if found, nullopt otherwise
    virtual std::optional<User> findById(int id) override;

    /// @brief Get all users
    /// @return Vector containing all users
    virtual std::vector<User> findAll() override;
    
    /// @brief Find a user by username
    /// 
    /// @param username Username to search for
    /// @return std::optional<User> User object if found, empty optional otherwise
    std::optional<User> findByUsername(const std::string& username);
};

#endif // USER_REPOSITORY_H